package com.ming.closeto.utils;

import java.math.BigDecimal;

public class FormatUtils {

    public static String formatSize(double size) {
        double kilo = size / 1024;
        if (kilo < 1) {
            return size + "B";
        }
        double magaByte = kilo / 1024;
        if (magaByte < 1) {
            BigDecimal bgByte = new BigDecimal(Double.toString(kilo));
            return bgByte.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";

        }
        double gigaM = magaByte  / 1024;
        if (gigaM < 1) {
            BigDecimal bgByte2 = new BigDecimal(Double.toString(magaByte));
            return  bgByte2.setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
        }

        double tear = gigaM / 1024 ;
        LogUtils.d(" tear size:" + tear);
        BigDecimal bgByte3 = new BigDecimal(Double.toString(gigaM));
        return bgByte3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
    }
}
